<@master template="master/master-loan"  title="怡亚通380金服__密码设置">
<div class="registerBar">
	<div class="mainbox">
    	<div class="registerBox">
        	<div class=""><span class="fs24">修改密码</span></div>
            <div class="inpLi">
            	<ul>
            		<li class="mt10">
                    	<div class="inpTit fl">手机号</div>
                    	<input name="mobile" type="text" class="dlInp" placeholder="请输入手机号" >
                    </li>
                    <li class="mt15">
                    	<div class="inpTit fl">设置密码</div>
                    	<input name="password" type="password" class="dlInp" placeholder="请输入6-16位密码">
                    </li>
                    <li class="mt15">
                    	<div class="inpTit fl">确认密码</div>
                    	<input name="confirmPassword" type="password" class="dlInp" placeholder="请填写6-16位密码">
                    </li>
                    <li class="mt15">
                    	<img src="/common/getCaptcha" id="Img" style="width:90px; height:34px;" class='fr yzmImg yamIco' style=" width:1.3rem;">
                    	<div class="inpTit fl">图形验证码</div>
                    	<input name="erifyCode" type="text" class="dlInp" style="width:130px" placeholder="请输入图形验证码">
                    </li>
                    <li class="mt15">
                    	<span id="verfyBtn" class="hqymz fr">获取验证码</span>
                    	<div class="inpTit fl">短信验证码</div>
                    	<input name="authCode" type="text" class="dlInp" style="width:130px" placeholder=" 请输入短信验证码">
                    </li>
                </ul>
                <a id="submitBtn" href="#" class="ldBtn mt20">确定</a>
            </div>
        </div>
    </div>
	</div>
	<@include file="/common/footer"/>
	<@js>  
	  $(document).ready(function(){
		  $("#Img").bind("click",function(){
		  	 var img = document.getElementById("Img");  
	         img.src = "/common/getCaptcha?rnd=" + Math.random();  
		  });
		  
		   $("#verfyBtn").bind("click",function(){
		  	 if(!validate())
					return false;
		  	 var mobile = $("input[name='mobile']").val();
    		 var erifyCode = $("input[name='erifyCode']").val();	
		  	 $.getJSON("/common/checkCaptcha",{captcha:erifyCode},function(result){
	    			if(result.data == true){
			    		$.getJSON("/common/checkUser",{mobile:mobile},function(result){
			    			if(result.data == true){
					   			$.getJSON("/msg/rest/sendAuthCode",{phone:mobile},function(result){
					    			if(result.data.success){
					   					$.actionDialog({message : '短信已发送成功，请注意查收'});
					   				}else{
					   					$.actionDialog({message : result.data.errMsg});
					   				}
					    		});
			   				}else{
			   					$.actionDialog({message : '该用户不存在'});
			   				}
			    		});
			    		
	   				}else{
	   					$.actionDialog({message : '图片验证码错误'});
	   				}
	    		});
		  	 
		  });
		  $("#submitBtn").bind("click",function(){
				var _this = $(this);
				if(!validate())
					return false;
				var authCode = $("input[name='authCode']").val();
	    		if(!authCode){
	    			$.actionDialog({message : '请输入短信验证码'});
	    			return false;
	    		}	
				var mobile = $("input[name='mobile']").val();
	    		var password = $("input[name='password']").val();
	    		var authCode = $("input[name='authCode']").val();	
	    		$.getJSON("/msg/rest/checkAuthCode",{phone:mobile,authCode:authCode},function(result){
	    			if(result.data.success){
	   					$.ajax({
			    			url:"/uc/rest/forgetPassword",
			    			dataType:"json",
			    			data:{mobile:mobile,password:password},
			    			success:function(msgResult){
			    				if(msgResult.data.success == true){
			    					window.location.href = "/uc/alertSuccess"
			    				}else{
			    					$.actionDialog({message : msgResult.data.errMsg});
			    				}
			    			}
			    		});
	   					
	   				}else{
	   					$.actionDialog({message : result.data.errMsg});
	   				}
	    		});
			
			});
			
			function validate(){
				var mobile = $("input[name='mobile']").val();
	    		var mobileCheck = $.fn.validate.mobile(mobile);
	    		if(!mobileCheck.isSuccess){
	    			$.actionDialog({message : mobileCheck.errorMsg});
	    			return false;
	    		}
	    		var password = $("input[name='password']").val();
	    		var passwordCheck = $.fn.validate.password(password);
	    		if(!passwordCheck.isSuccess){
	    			$.actionDialog({message : passwordCheck.errorMsg});
	    			return false;
	    		}
	    		var confirmPassword = $("input[name='confirmPassword']").val();
				if (null == confirmPassword || "" == confirmPassword) {
					$.actionDialog({message : '请再次输入登录密码'});
		    		return false;
				}	    		
	    		if (confirmPassword != password) {
		    		$.actionDialog({message : '两次密码输入不一致，请重新输入'});
		    		return false;
	    		}
	    		var erifyCode = $("input[name='erifyCode']").val();
	    		if(!erifyCode){
	    			$.actionDialog({message : '请输入图片验证码'});
	    			return false;
	    		}
	    		return true;
			}
			
				
		})
	</@js>
	<@jsRender/>  
</@master>